package biz.impl;

import java.util.List;

import biz.FoodTypeBiz;
import dao.FoodDao;
import dao.FoodTypeDao;
import dao.RateDao;
import dao.impl.FoodDaoImpl;
import dao.impl.FoodTypeDaoImpl;
import dao.impl.RateDaoImpl;
import entity.Food;
import entity.FoodType;
import entity.Rate;

public class FoodTypeBizImpl implements FoodTypeBiz{
	FoodTypeDao ftd = new FoodTypeDaoImpl();
	FoodDao fd = new FoodDaoImpl();
	RateDao rd = new RateDaoImpl();
	@Override
	public List<FoodType> queryAllFoodType() {
		List<FoodType> list = ftd.queryAllFoodType();
		for (FoodType foodType : list) {
			List<Food> foodList = fd.queryFoodByTypeId(foodType.getFtId());
			if(foodList!=null&&foodList.size()>0){
				foodType.setFoodList(foodList);
			}
			List<Rate> rateList = rd.queryRateByFoodTypeId(foodType.getFtId());
			if(rateList!=null&&rateList.size()>0){
				foodType.setRateList(rateList);
			}
		}
		return list;
	}

	public static void main(String[] args) {
		FoodTypeBizImpl impl = new FoodTypeBizImpl();
		FoodType foodType = impl.queryFoodTypeByFoodTypeId(6);
		System.out.println(foodType.getFoodTypeName());
//		for (FoodType foodType : list) {
//			System.out.println(foodType.getFoodTypeName());
//		}
	}
	@Override
	public FoodType queryFoodTypeByFoodTypeId(int foodTypeId) {
		FoodType foodType = ftd.queryFoodTypeByFoodTypeId(foodTypeId);
		List<Food> foodList = fd.queryFoodByTypeId(foodType.getFtId());
		if(foodList!=null&&foodList.size()>0){
			foodType.setFoodList(foodList);
		}
		List<Rate> rateList = rd.queryRateByFoodTypeId(foodType.getFtId());
		if(rateList!=null&&rateList.size()>0){
			foodType.setRateList(rateList);
		}
		return foodType;
	}

	@Override
	public void addFoodType(FoodType foodtype) {
		ftd.addFoodType(foodtype);
		
	}

	@Override
	public void deleteFoodType(int ftid) {
		ftd.deleteFoodType(ftid);
	}

	@Override
	public void updateFoodType(FoodType foodtype) {
		ftd.updateFoodType(foodtype);
		
	}

}
